<template>
  <a-modal
    title="物资用量确认单选择"
    :visible="visible"
    class="pub-middle-dialog"
    @ok="handleOk"
    @cancel="visible=false"
  >
    <searchData
      :search-data="searchArr"
      @search="search"
    />
    <a-table
      :pagination="false"
      :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange ,type:'radio'}"
      :columns="columns"
      :data-source="tableData"
      row-key="id"
    >
      <span
        slot="num"
        slot-scope="text, record, index"
      >{{ index + 1 }}</span>
    </a-table>
    <pagination
      v-model="pageNo"
      :total="totalSize"
      :page-size.sync="pageSize"
      @change="handlePageChange"
      @showSizeChange="showSizeChange"
    />
  </a-modal>
</template>
<script>
import { concreteDosageList } from '@/api/material/settlement/settlement'

export default {
	name:'a'+Date.now(),
    data: function() {
        return {
            pageNo: 1,
            pageSize: 10,
            queryParam: {},
            totalSize: 0,
            visible: false,
            tableData: [],
            columns: [
                {
                    title: '序号',
                    scopedSlots: { customRender: 'num' }
                },
                {
                    title: '物资用量确认单编码',
                    dataIndex: 'code'
                }
            ],
            searchArr: [
                {
                    name: '物资用量确认单编码',
                    value: 'code',
                    type: 'input'
                }
            ],
            selectedRowKeys: [],
            selectRow: null
        }
    },
    methods: {
        open: function() {
            this.visible = true
            this.search()
            this.selectedRowKeys = []
        },
        handleOk: function() {
            this.visible = false
            this.$emit('getDosage', this.selectRow)
        },
        list: function(params) {
            let _this = this
            let searchData = Object.assign({
                pageSize: _this.pageSize,
                pageNo: _this.pageNo,
                auditStatus: 'PAST'
            }, params, this.queryParam)
            concreteDosageList(searchData).then(res => {
                if (res.code === 200) {
                    _this.tableData = res.data
                    _this.totalSize = res.totalSize
                }
            })
        },
        search(val) {
            this.pageNo = 1
            this.queryParam = val
            this.list(val)
        },
        handlePageChange(pageNo, pageSize) {
            this.pageNo = pageNo
            this.list()
            this.selectedRowKeys = []
        },
        showSizeChange(pageNo, pageSize) {
            this.pageNo = 1
            this.pageSize = pageSize
            this.list()
        },
        onSelectChange(selectedRowKeys, selectedRows) {
            this.selectRow = selectedRows[0]
            this.selectedRowKeys = selectedRowKeys
        }
    }
}
</script>
